home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / pmlsrc23.zoo / pmlsrc / floor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-19  |  1.3 KB  |  83 lines

  1. /*
  2.  * floor and ceil
  3.  *     from pete housels posting
  4.  */
  5.  
  6. #if !defined (__M68881__) || !defined (sfp004)
  7. #if __STDC__
  8. double    modf(double, double *);
  9. #else
  10. double    modf();
  11. #endif
  12.  
  13. double
  14. floor(x)
  15. double x;
  16. {
  17.  double fract;
  18.  
  19.  fract = modf(x, &x);
  20.  
  21.  if(fract < 0.0)
  22.     return x - 1.0;
  23.  else
  24.     return x;
  25. }
  26.  
  27. double
  28. ceil(x)
  29. double x;
  30. {
  31.     return(-floor(-x));
  32. }
  33. #endif
  34.  
  35. #ifdef __M68881_
  36.  
  37. double ceil (double x)
  38. {
  39.   int rounding_mode, round_up;
  40.   double value;
  41.  
  42.   __asm volatile ("fmove%.l fpcr,%0"
  43.           : "=dm" (rounding_mode)
  44.           : /* no inputs */ );
  45.   round_up = rounding_mode | 0x30;
  46.   __asm volatile ("fmove%.l %0,fpcr"
  47.           : /* no outputs */
  48.           : "dmi" (round_up));
  49.   __asm volatile ("fint%.x %1,%0"
  50.           : "=f" (value)
  51.           : "f" (x));
  52.   __asm volatile ("fmove%.l %0,fpcr"
  53.           : /* no outputs */
  54.           : "dmi" (rounding_mode));
  55.   return value;
  56. }
  57.  
  58. double floor (double x)
  59. {
  60.   int rounding_mode, round_down;
  61.   double value;
  62.  
  63.   __asm volatile ("fmove%.l fpcr,%0"
  64.           : "=dm" (rounding_mode)
  65.           : /* no inputs */ );
  66.   round_down = (rounding_mode & ~0x10)
  67.         | 0x20;
  68.   __asm volatile ("fmove%.l %0,fpcr"
  69.           : /* no outputs */
  70.           : "dmi" (round_down));
  71.   __asm volatile ("fint%.x %1,%0"
  72.           : "=f" (value)
  73.           : "f" (x));
  74.   __asm volatile ("fmove%.l %0,fpcr"
  75.           : /* no outputs */
  76.           : "dmi" (rounding_mode));
  77.   return value;
  78. }
  79. #endif __M68881__
  80.  
  81. #ifdef    sfp004
  82. #endif    sfp004
  83.